﻿using MediatR;
using T.Materials.API.Application.Command.MaterialStatisticsCommand;
using T.Materials.Domain.Model;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.API.Application.CommandHandler.MaterialStatisticsCommandHandler
{
    /// <summary>
    /// 更新物资统计命令处理器
    /// </summary>
    public class UpdateMaterialStatisticsCommandHandler : IRequestHandler<UpdateMaterialStatisticsCommand, int>
    {
        /// <summary>
        /// 物资统计仓储接口
        /// </summary>
        protected readonly IMaterialStatisticsRepository materialStatisticsRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialStatisticsRepository">物资统计仓储接口</param>
        public UpdateMaterialStatisticsCommandHandler(IMaterialStatisticsRepository materialStatisticsRepository)
        {
            this.materialStatisticsRepository = materialStatisticsRepository;
        }

        /// <summary>
        /// 处理更新物资统计命令
        /// </summary>
        /// <param name="request">更新物资统计命令</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(UpdateMaterialStatisticsCommand request, CancellationToken cancellationToken)
        {
            return await materialStatisticsRepository.UpdateAsync(new MaterialStatistics()
            {
                MaterialStatisticsId=request.MaterialStatisticsId,
                CompanyID=request.CompanyID,
                User_Id=request.User_Id,
                NameGoods=request.NameGoods,
                MaterialStatisticsType=request.MaterialStatisticsType,
                MaterialStatisticsMaterial=request.MaterialStatisticsMaterial,
                MaterialStatistSpecificat=request.MaterialStatistSpecificat,
                Country=request.Country,
                Economize=request.Economize,
                PurchaseQuantity=request.PurchaseQuantity,
                QuantiReceived=request.QuantiReceived,
                BalanceQuantity=request.BalanceQuantity,
                ProcuremenTime=request.ProcuremenTime,
                UpdatedBy=request.UpdatedBy,
                UpdatedDate=DateTime.Now
            });
        }
    }
}
